var WxNewsModel = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: '新闻',
		winid:'WxNews_EditForm',
		formid:'WxNews_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/contest18/mgr/wxNews',
    title: '新闻',
    idField: "newsContent",
    titleField: "newsContent",
    toolbar: 'WxNews_Toolbar',
    datagrid: 'WxNews_Grid' 
}); 
 
WxNewsModel.reload =function() {
	ReloadList_WxNews();
	$('#WxNews_EditForm').dialog('close'); 
} 


function Del_WxNews() {
    var _checkedItems = $('#WxNews_Grid').datagrid('getChecked');
    var _delcount=0;
    var _names = '';
    if(_checkedItems.length<1) {
        $.messager.alert('提示', '请选择需要删除的数据!' );
        return;
    }
    $.each(_checkedItems, function(index, item){
        _names +='<br/>'+ item[WxNewsModel.titleField] ;
    });
    var url = WxNewsModel.url+'/del' ;
    $.messager.confirm('确定要删除如下信息?', '' + _names , function (r) {
        if (r) {
           var postdata={
                "reqBody": {} ,
                "reqHead": {
                    "sysCode": "contest18_test"
                }
            }
            $.each(_checkedItems, function(index, item){
                postdata.reqBody=item;
                Onluy.ajax.postData(url,postdata,  function(result){
                    if (result.rspCode ==0) {
                        _delcount++;
                    }
                },function(error){  } );
            });
            $.messager.alert('提示', '成功删除'+_delcount+'条数据!' );
            ReloadList_WxNews();
        }
    });
}

function ShowEditForm_WxNews(type) {
     switch (type) {
        case  1:
            var checkedItems = $('#WxNews_Grid').datagrid('getChecked');
            if(checkedItems.length>1){
                $.messager.alert('提示', '只能选择一条记录修改!' );
                return;
            }
WxNewsModel.selRow = checkedItems[0];
WxNewsModel.postAction = 'update';
            break;

        case  0:
        default:
            WxNewsModel.selRow = {}
            WxNewsModel.postAction = 'add';
            break;
    }

    $('#WxNews_EditForm_fm').form('clear' );
    WxNewsModel.selRow['typeId'] = getQueryStringByName('typeId');
    $('#WxNews_EditForm_fm').form('load', WxNewsModel.selRow);
    $('#WxNews_EditForm').dialog({
        resizable: false,
        maximizable: false
    })
    .dialog('open')
    .dialog('setTitle', (WxNewsModel.postAction == 'add') ? '新增' + WxNewsModel.title : '修改' + WxNewsModel.selRow[WxNewsModel.titleField]);
}

function save_WxNews() {
    WxNewsModel.submit();
}


function WxNewsSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#WxNews_Grid').datagrid('reload');
    }
}
 
function ReloadList_WxNews() {
    $('#WxNews_Grid').datagrid('reload');
}
 


$(function () {   
    $('#WxNews_Grid').datagrid({
        pageSize: 10,
        fit: true,
        checkOnSelect: true,
        selectOnCheck: true,
        singleSelect: false,
        checkbox: true,
        fitColumns: true,
        pagination: true,
        method: 'post',
        url:  WxNewsModel.url+'/list',
        loader:WxNewsModel.Loader,
        toolbar: '#WxNews_Toolbar', 
        columns: [
            [
                { field: 'ck',  checkbox: true },
                { field: 'menuIcon', title: '图标', width:40, align: 'left' ,
                    formatter: function (value, rec) {
                        var htmlstr='<img   src="'+"/Images/icos/home_ico_2.png"+'"  />';
                        return htmlstr;
                    }},
            
            { field: 'newsId', title: '新闻标识', width:100, align: 'left',sortable:true },
            { field: 'newsName', title: '新闻标题', width:100, align: 'left',sortable:true },
            { field: 'inDate', title: '录入日期', width:100, align: 'left',sortable:true },
            { field: 'upDate', title: '修改日期', width:100, align: 'left',sortable:true },
            { field: 'newsRemark', title: '新闻备注', width:100, align: 'left',sortable:true }
            ]
        ],

        
        onLoadError: function (res) {
        	WxNewsModel.ShowException(res); 
        },
        onLoadSuccess: function (data) {
           if(data.success){ }
           else if(data.msg){
        		 $.messager.alert('加载错误', data.msg );
        	} 
        },
        onBeforeLoad: function (param) { 
        	$('#WxNews_Grid').datagrid('clearSelections');

            param['typeId'] = getQueryStringByName('typeId');
            param['catchKey'] = Math.random();
            param['name'] = $('#WxNews_ss').searchbox('getName');
            param['value'] = $('#WxNews_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#WxNews_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 10, //每页显示的记录条数，默认为10
        pageList: [10,20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字  
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



